package cn.iocoder.yudao.module.system.config;

import cn.iocoder.yudao.module.system.framework.web.UserActivityInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 用户活动记录自动配置类
 * 
 * @author 系统开发团队
 */
@Configuration
@EnableConfigurationProperties(UserActivityProperties.class)
@ConditionalOnProperty(prefix = "yudao.user-activity", name = "enable", havingValue = "true", matchIfMissing = true)
@EnableAspectJAutoProxy
public class YudaoUserActivityAutoConfiguration implements WebMvcConfigurer {

    @Resource
    private UserActivityProperties userActivityProperties;

    @Bean
    public UserActivityInterceptor userActivityInterceptor() {
        return new UserActivityInterceptor(userActivityProperties);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userActivityInterceptor())
                .addPathPatterns("/**");
    }
}